<template>
  <div class="infoSearch">
    <el-form
      :inline="true"
      :model="formData"
      class="demo-form-inline"
      ref="formData"
      style="width:100%"
    >
      <el-form-item>
        <el-input v-model="formData.name" placeholder="资讯名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="formData.gameId" filterable placeholder="输入游戏名搜索">
          <el-option
            v-for="item in options"
            :key="item.id"
            :label="item.gameName"
            :value="item.id"
            style="width:300px"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-select v-model="formData.type" filterable placeholder="资讯类型">
          <el-option
            v-for="item in infoOptions"
            :key="item.id"
            :label="item.label"
            :value="item.id"
            style="width:120px"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="dataSearch" @click="dataSearch(formData)">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button class="addNewgame" type="primary" @click="addActivity()">添加游戏资讯</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getOptionList } from "@/api/gameManage";
export default {
  data() {
    return {
      formData: {
        gameId: "",
        name: "",
        type: "",
        page: 1,
        limit: 20
      },
      options: [],
      loading: false,
      infoOptions: [
        {
          id: 0,
          label: "全部"
        },
        {
          id: 1,
          label: "游戏资讯"
        },
        {
          id: 2,
          label: "活动"
        },
        {
          id: 3,
          label: "游戏攻略"
        }
      ]
    };
  },
  mounted() {
    getOptionList().then(res => {
      this.options = res.data.list;
    });
  },
  methods: {
    // 查询
    dataSearch() {
      this.$refs.formData.validate(valid => {
        if (valid) {
          this.$store.commit("SET_SEARCH", this.formData);
          this.$emit("searchList", this.formData);
        }
      });
    },
    addActivity() {
      this.$emit("showaddinfoDialog");
    }
  }
};
</script>
<style lang="scss" scoped>
.infoSearch {
  width: 92%;
}
.el-form-item {
  margin-bottom: 0;
}
.el-button--primary {
  background-color: #409eff;
  border-color: #409eff;
}
.addNewgame,
.dataSearch {
  padding: 0 15px;
  height: 30px;
  font-size: 13px;
}

.el-select-dropdown__item {
  white-space: normal;
  height: auto;
}
.el-date-editor--daterange.el-input,
.el-date-editor--daterange.el-input__inner,
.el-date-editor--timerange.el-input,
.el-date-editor--timerange.el-input__inner {
  width: 250px;
}
</style>